﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.BarterSystem.Barterables.TransferPrisonerBarterable
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.BarterSystem.Barterables
{
  public class TransferPrisonerBarterable : Barterable
  {
    [SaveableField(10)]
    private readonly Hero _prisonerCharacter;
    [SaveableField(20)]
    private readonly Hero _opponentHero;
    [SaveableField(30)]
    private readonly PartyBase _otherParty;

    public override string StringID => "transfer_prisoner_barterable";

    public TransferPrisonerBarterable(
      Hero prisonerCharacter,
      Hero owner,
      PartyBase ownerParty,
      Hero opponentHero,
      PartyBase otherParty)
      : base(owner, ownerParty)
    {
      this._prisonerCharacter = prisonerCharacter;
      this._opponentHero = opponentHero;
      this._otherParty = otherParty;
    }

    public override TextObject Name
    {
      get
      {
        TextObject parent = new TextObject("{=g5bzJjd5}Transfer {PRISONER.NAME}");
        StringHelpers.SetCharacterProperties("PRISONER", this._prisonerCharacter.CharacterObject, parent);
        return parent;
      }
    }

    public override int GetUnitValueForFaction(IFaction faction)
    {
      int num = Campaign.Current.Models.RansomValueCalculationModel.PrisonerRansomValue(this._prisonerCharacter.CharacterObject);
      return faction == this.OriginalOwner?.Clan || faction == this.OriginalOwner?.MapFaction || faction == this.OriginalParty.MapFaction ? -num : num;
    }

    public override ImageIdentifier GetVisualIdentifier()
    {
      return new ImageIdentifier(CharacterCode.CreateFrom((BasicCharacterObject) this._prisonerCharacter.CharacterObject));
    }

    public override string GetEncyclopediaLink() => this._prisonerCharacter.EncyclopediaLink;

    public override void Apply()
    {
      if (this._otherParty != null && this._otherParty.MapFaction.IsAtWarWith(this._prisonerCharacter.MapFaction))
        TransferPrisonerAction.Apply(this._prisonerCharacter.CharacterObject, this.OriginalParty, this._otherParty);
      else
        Debug.FailedAssert("Failed to transfer prisoner through barter", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\BarterSystem\\Barterables\\TransferPrisonerBarterable.cs", nameof (Apply), 70);
    }

    internal static void AutoGeneratedStaticCollectObjectsTransferPrisonerBarterable(
      object o,
      List<object> collectedObjects)
    {
      ((Barterable) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._prisonerCharacter);
      collectedObjects.Add((object) this._opponentHero);
      collectedObjects.Add((object) this._otherParty);
    }

    internal static object AutoGeneratedGetMemberValue_prisonerCharacter(object o)
    {
      return (object) ((TransferPrisonerBarterable) o)._prisonerCharacter;
    }

    internal static object AutoGeneratedGetMemberValue_opponentHero(object o)
    {
      return (object) ((TransferPrisonerBarterable) o)._opponentHero;
    }

    internal static object AutoGeneratedGetMemberValue_otherParty(object o)
    {
      return (object) ((TransferPrisonerBarterable) o)._otherParty;
    }
  }
}
